<?php
class Sanpham_model extends CI_Model{    
public  $table = 'sanpham';    
public  $table1='category';    
public function  getProductByCate($cat_ids) {				
$cat_ids = explode(',', $cat_ids);        
return $this->db            
->where_in('cate_id',$cat_ids)            
->limit(3)            
->order_by('rand()')            
->get($this->table)            
->result_array();    
}    
public function  getProductByCate_1($cate_id) {        
return $this->db            
->where('cate_id',$cate_id)            
->limit(3)            
->order_by('id','asc')            
->get($this->table)            
->result_array();        
//select * from sanpham where cate_id=$cate_id,#prentid =2    
}    
public function  getProductByCate_2($cate_id) {        
return $this->db            
->where('cate_id',$cate_id)            
->limit(3)            
->order_by('id','asc')            
->get($this->table)            
->result_array();        
//select * from sanpham where cate_id=$cate_id,#prentid =2    
}    
public function  menu_left($cate_id) {        
$cate_ids = array($cate_id);        
$rows = $this->db            
->select('id')            
->where('prent_id',$cate_id)            
->get('category')            
->result_array();        
foreach($rows as $row){            
$cate_ids[] = $row['id'];        
}        
return $this->db            
->where_in('cate_id', $cate_ids)            
->order_by('id','asc')            
->limit(24)            
->get($this->table)            
->result_array();        
//select * from sanpham where cate_id=$cate_id,#prentid =2    
}    /*mua he*/    
public function  category($prent_id) {        
return $this->db            
->where('prent_id',$prent_id)            
->get($this->table1)            
->result_array();        
//select * from sanpham where cate_id=$cate_id    
}    
function getCatByParent($prent_id) {        
return $this->db            
->where('prent_id',$prent_id)            
->get($this->table1)            
->result_array();    
}    
public function  muahe($prent_id) {        
return $this->db            
->where('prent_id',$prent_id)            
->where('id',2)            
->get($this->table1)            
->result_array();        
//select * from sanpham where cate_id=$cate_id    
}    
public function jointable($prent_id){        
return $this->db            
->select('*')            
->from('sanpham')            
->join('category',' sanpham.cate_id = category.id')            
->limit(8)            
->order_by('sanpham.id','desc')            
->where ('prent_id',$prent_id)            
->get()            
->result_array();       
// return $this->db        
//        ->select ('*')        // select * from sanpham where    }    
/*    public function  category_id($cat_id) {        return $this->db            ->where('id',$cat_id)            ->get($this->table1)            ->result_array();        //select * from sanpham where cate_id=$cate_id    }    */    /*phan trang*/
}
}